﻿#pragma once
#pragma execution_character_set("utf-8")

#include <QWidget>
#include <QWidget>
#include <QPushButton>
#include <QlistView>

class LogModel;

enum class LogType {
    Debug, Info, Warn, Error, Fatal
};

class LogWidget : public QWidget
{
    Q_OBJECT

public:
    explicit LogWidget(QWidget *parent = Q_NULLPTR);
    ~LogWidget();

public slots:
    void onInfoClick();
    void onWarnClick();
    void onErrorClick();
    void onMessage(const QString strMsg);
    void onMessageInfo(const QString strMsg);
    void onMessageWarn(const QString strMsg);
    void onMessageError(const QString strMsg);

private:
    void updateCount();
    void setupUI();
    void initConnect();

signals:
    bool sigMessageInfo(int index, const QString item);
    bool sigMessageWarn(int index, const QString item);
    bool sigMessageError(int index, const QString item);

private:    
    LogType mCurLogType = LogType::Info;
    LogModel *mInfoModel = nullptr;
    LogModel *mWarnModel = nullptr;
    LogModel *mErrorModel = nullptr;
    QThread* h_this, * h_info, * h_warn, * h_error;

private:
    QPushButton* pbtnInfo;
    QPushButton* pbtnWarn;
    QPushButton* pbtnError;
    QListView* lstvLog;

};
